<?php

class cms_tag_model extends CI_Model {

    protected $_instance = array(
        'table' => 'cms_tag',
        'primaryKey' => 'id',
    );
    public $_data = null;
    protected $_indexes = array(
        "INDEX,FOLLOW",
        "INDEX,NOFOLLOW",
        "NOINDEX,FOLLOW",
        "NOINDEX,NOFOLLOW"
    );

    public function get_url($tag = null) {
        if (empty($tag)) {
            return null;
        }
        return BASE_URL . 'tag/' . $tag . '.html';
    }

    public function get_tags($reload = false) {
        $CI = & get_instance();
        $list_tag = null;
        if ($reload) {
            $query = $this->db->query("SELECT * FROM site_tag ORDER BY name ASC");
            foreach ($query->result() as $row) {
                $list_tag[$row->id] = $row;
            }
            $query->free_result();
            $CI->st_registry->setKey('medical/site_tag/collection', $list_tag, GLOBAL_CACHE_DURATION);
        } else {
            $list_tag = $CI->st_registry->getKey('medical/site_tag/collection');
            if (empty($list_tag)) {
                return $this->get_tags(true);
            }
        }
        return $list_tag;
    }
}

?>